
package cfop;

import bd.ConBdSqlS;
import bd.Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Camilo
 */
public class CfopDao implements Dao{
    protected Connection con;

  public CfopDao() throws SQLException {
    this.con = ConBdSqlS.getConexao();
  }

  public Cfop getCfop(String cf) throws SQLException {
    Cfop cfop = new Cfop();//instancia um novo objeto
    //    Código SQL
    String sql = "SELECT cfop, cfop_entrada "
            + "FROM cfop "
            + "WHERE (cfop LIKE ?);";

    PreparedStatement stmt = this.con.prepareStatement(sql);
    stmt.setString(1, cf);//Define o critério da consulta
    ResultSet rs = stmt.executeQuery();//executa a consulta SQL
//    percorre os registros da tabela e seta os valores das classes
    while (rs.next()) {
      cfop.setCfop(rs.getString("cfop"));
      cfop.setCfop_entrada(rs.getString("cfop_entrada"));
    }
//    fecha as conexões
    rs.close();
    stmt.close();

    return cfop;
  }

  @Override
  public List<Object> getLista(String param) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public void altera(Object c1) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public void remove(Object c1) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public void adicionar(Class pme) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
  }
}
